<?php

namespace app\Api\controller;

use app\common\model\Account;
use app\common\model\Coin;
use app\common\model\Inverstment;
use think\Controller;
use think\Request;
use think\Validate;

class Part extends Base
{
    //立即预约
    public function join()
    {
        $params   = $this->request->param();
        $validate = new Validate([
            'number' => 'require|number',
        ], [
            'number.require' => '请填写金额'
        ]);
        if (!$validate->check($params)) {
            return $this->fail($validate->getError(), 4010);
        }
        $number  = $params['number'];
        $user_id = $this->user()->id;
        $invest  = Inverstment::find();
        $invest_coin = strtoupper($invest['invest_name']);
        $use_coin    = strtoupper($invest['use_name']);
        //判断一下余额够不够
        $check1 = Account::checkBalance($user_id, $use_coin, $number);
        if (!$check1) return $this->fail('消耗代币余额不足', 4011);
        //判断投资余额
        $check2 = Account::checkBalance($user_id, $invest_coin, $number);
        if (!$check2) return $this->fail('投资代币余额不足', 4012);


    }


}
